///////////////////////////////////////
//    Autor: Mato Kormuth              //
//    (C) Mato Programs 2011        //
//////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Marble_Blast_Mods_Creator
{
    public partial class Settings : Form
    {
        bool gimpmanual;
        public Settings()
        {
            InitializeComponent();
        }

        private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            textBox1.Text = folderBrowserDialog1.SelectedPath.ToString();
            //MBMCSettings.Default.path_to_mbg = textBox1.Text;
            //MBMCSettings.Default.Save();
            //MBMCSettings.Default.Upgrade();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MBMCSettings.Default.path_to_mbg = textBox1.Text;
            MBMCSettings.Default.path_to_torqueconstructor = textBox2.Text;
            MBMCSettings.Default.path_to_audacity = textBox3.Text;
            MBMCSettings.Default.path_to_gimp = textBox4.Text;
            MBMCSettings.Default.path_to_terragen = textBox5.Text;
            MBMCSettings.Default.gimpmanual = gimpmanual;
            MBMCSettings.Default.Save();
            MBMCSettings.Default.Upgrade();
            //copy directory
            //MatoPrograms.Comp.DirectoryCopy dc = new MatoPrograms.Comp.DirectoryCopy();
       //d
            //bool b = CopyDirectory(textBox1.Text, Application.StartupPath + "/data/templates/Marble Blast Gold", true);
        }

        public static bool CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting)
        {
            bool ret = false;
            try
            {
                SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
                DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";

                if (Directory.Exists(SourcePath))
                {
                    if (Directory.Exists(DestinationPath) == false)
                        Directory.CreateDirectory(DestinationPath);

                    foreach (string fls in Directory.GetFiles(SourcePath))
                    {
                        FileInfo flinfo = new FileInfo(fls);
                        flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);
                    }
                    foreach (string drs in Directory.GetDirectories(SourcePath))
                    {
                        DirectoryInfo drinfo = new DirectoryInfo(drs);
                        if (CopyDirectory(drs, DestinationPath + drinfo.Name, overwriteexisting) == false)
                            ret = false;
                    }
                }
                ret = true;
            }
            catch (Exception ex)
            {
                ret = false;
            }
            return ret;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            folderBrowserDialog2.ShowDialog();
            textBox2.Text = folderBrowserDialog2.SelectedPath;
        }

        private void folderBrowserDialog2_HelpRequest(object sender, EventArgs e)
        {
            
        }

        private void button4_Click(object sender, EventArgs e)
        {
            folderBrowserDialog3.ShowDialog();
            textBox3.Text = folderBrowserDialog3.SelectedPath;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            
            folderBrowserDialog4.ShowDialog();
            gimpmanual = true;
            textBox4.Text = folderBrowserDialog4.SelectedPath;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            folderBrowserDialog5.ShowDialog();
            textBox5.Text = folderBrowserDialog5.SelectedPath;
        }

        private void folderBrowserDialog3_HelpRequest(object sender, EventArgs e)
        {
            textBox3.Text = folderBrowserDialog3.SelectedPath;
        }

        private void folderBrowserDialog4_HelpRequest(object sender, EventArgs e)
        {
            textBox4.Text = folderBrowserDialog4.SelectedPath;
        }

        private void Settings_Load(object sender, EventArgs e)
        {
            textBox3.Text = Application.StartupPath + "/data/apps/audacity";
            textBox4.Text = Application.StartupPath + "/data/apps/gimp";
            textBox5.Text = Application.StartupPath + "/data/apps/terragen";
        }
    }
}